home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / libs / sphigs / sph_srgp.lha / srgp / examples / test_locator.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-01-09  |  4.6 KB  |  184 lines

  1. /**
  2. This program places the keyboard in RAW EVENT mode.
  3.  
  4. You use the keyboard to control the locator's mode:
  5.     i -- inactive
  6.     s -- sample
  7.     e -- event
  8.  
  9. You also use the keyboard to control the echo attribute:
  10.     c -- cursor
  11.     l -- rubber line
  12.     r -- rubber rect
  13.  
  14. You can control button mask in this way:
  15.     1 -- toggles the status of the LEFT button in the button mask
  16.              ... etc. ...   for 2 (MIDDLE) and 3 (RIGHT)
  17.  
  18. You quit by typing:
  19.     q -- QUIT
  20. **/
  21.  
  22.  
  23. #include "srgp.h"
  24.  
  25.  
  26. static deluxe_locator_measure dlm;
  27. static char buffer[100];
  28. static char kmstring[2];
  29. static deluxe_keyboard_measure dkm;
  30.  
  31. static int lineheight, textw, texta, textd;
  32.  
  33. static int timeout;
  34.  
  35. static int locatorMode = INACTIVE;
  36. static char *modeNames[] = {"INACTIVE", "SAMPLE", "EVENT"};
  37.  
  38. static int locatorButtonMask = LEFT_BUTTON_MASK;
  39.  
  40.  
  41. static void DisplayLocatorMeasure ()
  42. {
  43.    int y = 400;
  44.  
  45.    SRGP_setColor (COLOR_WHITE);
  46.    SRGP_fillRectangleCoord (0, (400-(7*lineheight)-textd), 1000, 400);
  47.    
  48.    SRGP_setColor (COLOR_BLACK);
  49.  
  50.    y -= lineheight;
  51.    sprintf (buffer, "LOCATOR MODE: %s", modeNames[locatorMode]);
  52.    SRGP_text (SRGP_defPoint(10,y), buffer);
  53.  
  54.    if (locatorMode == INACTIVE) {
  55.       y -= 2*lineheight;
  56.       SRGP_text (SRGP_defPoint(10,y), 
  57.          "For instructions on how to use this demo,");
  58.       y -= lineheight;
  59.       SRGP_text (SRGP_defPoint(10,y), 
  60.          "    you must consult the demo README file,");
  61.       y -= lineheight;
  62.       SRGP_text (SRGP_defPoint(10,y), 
  63.          "    or the comment in the source file itself.");
  64.       y -= lineheight;
  65.       SRGP_text (SRGP_defPoint(10,y), 
  66.          "Use 'q' to quit, and then read the instructions.");
  67.       return;
  68.    }
  69.  
  70.    y -= lineheight;
  71.    sprintf (buffer, "Button mask: %s  %s  %s", 
  72.         (locatorButtonMask&LEFT_BUTTON_MASK) == 0 ? "----" : "LEFT",
  73.         (locatorButtonMask&MIDDLE_BUTTON_MASK) == 0 ? "------" : "MIDDLE",
  74.         (locatorButtonMask&RIGHT_BUTTON_MASK) == 0 ? "-----" : "RIGHT");
  75.    SRGP_text (SRGP_defPoint(10,y), buffer);
  76.  
  77.    y -= lineheight;
  78.    sprintf (buffer, "Position: %3d, %3d", dlm.position.x, dlm.position.y);
  79.    SRGP_text (SRGP_defPoint(10,y), buffer);
  80.  
  81.    y -= lineheight;
  82.    sprintf (buffer, "Button chord: %d, %d, %d", 
  83.         dlm.button_chord[0], dlm.button_chord[1], dlm.button_chord[2]);
  84.    SRGP_text (SRGP_defPoint(10,y), buffer);
  85.  
  86.    y -= lineheight;
  87.    sprintf (buffer, "Button of last transition: %d", 
  88.         dlm.button_of_last_transition);
  89.    SRGP_text (SRGP_defPoint(10,y), buffer);
  90.  
  91.    y -= lineheight;
  92.    sprintf (buffer, "Modifier chord: %d, %d, %d", 
  93.         dlm.modifier_chord[0], dlm.modifier_chord[1], 
  94.         dlm.modifier_chord[2]);
  95.    SRGP_text (SRGP_defPoint(10,y), buffer);
  96.  
  97.    y -= lineheight;
  98.    sprintf (buffer, "Timestamp: %8d seconds, %2d ticks", 
  99.         dlm.timestamp.seconds, dlm.timestamp.ticks);
  100.    SRGP_text (SRGP_defPoint(10,y), buffer);
  101. }
  102.  
  103.  
  104.  
  105.  
  106.  
  107. main()
  108. {
  109.    SRGP_begin ("Locator exercise", 600, 400, 1, FALSE);
  110.  
  111.  
  112.    SRGP_setInputMode (KEYBOARD, EVENT);
  113.    SRGP_setKeyboardProcessingMode (RAW);
  114.  
  115.    dkm.buffer = kmstring;
  116.    dkm.buffer_length = 2;
  117.  
  118.    SRGP_inquireTextExtent ("High", &textw, &texta, &textd);
  119.    lineheight = texta + textd;
  120.  
  121.    SRGP_setInputMode (LOCATOR, INACTIVE);
  122.    DisplayLocatorMeasure();
  123.  
  124.    while (1) {
  125.       timeout = (locatorMode == SAMPLE) ? 20 : -1;
  126.       switch (SRGP_waitEvent (timeout)) {
  127.        case NO_DEVICE:
  128.      SRGP_sampleDeluxeLocator (&dlm);
  129.      DisplayLocatorMeasure();
  130.      break;
  131.        case LOCATOR:
  132.      SRGP_getDeluxeLocator (&dlm);
  133.      DisplayLocatorMeasure();
  134.      break;
  135.        case KEYBOARD:
  136.      SRGP_getDeluxeKeyboard (&dkm);
  137.      switch (dkm.buffer[0]) {
  138.       case '1':
  139.         locatorButtonMask ^= LEFT_BUTTON_MASK;
  140.         SRGP_setLocatorButtonMask (locatorButtonMask);
  141.         DisplayLocatorMeasure();
  142.         break;
  143.       case '2':
  144.         locatorButtonMask ^= MIDDLE_BUTTON_MASK;
  145.         SRGP_setLocatorButtonMask (locatorButtonMask);
  146.         DisplayLocatorMeasure();
  147.         break;
  148.       case '3':
  149.         locatorButtonMask ^= RIGHT_BUTTON_MASK;
  150.         SRGP_setLocatorButtonMask (locatorButtonMask);
  151.         DisplayLocatorMeasure();
  152.         break;
  153.       case 'i': 
  154.         SRGP_setInputMode (LOCATOR, INACTIVE); 
  155.         locatorMode = INACTIVE;
  156.         DisplayLocatorMeasure();
  157.         break;
  158.       case 's': 
  159.         SRGP_setInputMode (LOCATOR, SAMPLE); 
  160.         locatorMode = SAMPLE;
  161.         DisplayLocatorMeasure();
  162.         break;
  163.       case 'e': 
  164.         SRGP_setInputMode (LOCATOR, EVENT);
  165.         locatorMode = EVENT;
  166.         DisplayLocatorMeasure();
  167.         break;
  168.       case 'c': 
  169.         SRGP_setLocatorEchoType (CURSOR);
  170.         break;
  171.       case 'l': 
  172.         SRGP_setLocatorEchoType (RUBBER_LINE);
  173.         break;
  174.       case 'r': 
  175.         SRGP_setLocatorEchoType (RUBBER_RECT);
  176.         break;
  177.       case 'q': 
  178.         SRGP_end();
  179.         exit(0);
  180.      }
  181.       }
  182.    }
  183. }
  184.